<template>
	<view class="address-form" :style="{minHeight:windowHeight+'px'}">
		<!-- <view class="head">
			<image src="../../../static/jiaotou1.png" @click="gotoPage('/pages/user/index/index')"></image>
			<text>设置</text>
		</view> -->
		<!-- <view class="item">
			@click="gotoPage('/pages/user/set/accountsSecurity/accountsSecurity')"
			<view class="item-content" @click="showIntegral" >
				<text>账户与安全</text>
				<image src="../../../static/jiantou3.png"></image>
			</view>
			
			<view class="item-content" @click="gotoPage('/pages/user/set/policyAgreement/policyAgreement')">
				<text>政策协议</text>
				<image src="../../../static/jiantou3.png"></image>
			</view>
		</view> -->
		<view class="item1">
			<!-- <view class="item-content" >
				<view>账户与安全</view>
				<view>当前版本号1.3.1</view>
				<image src="../../../static/jiantou3.png"></image>
			</view> -->
			
			<view class="item-content" @click="gotoPage('/pages/user/set/policyAgreement/policyAgreement')">
				<text>政策协议</text>
				<image src="../../../static/jiantou3.png"></image>
			</view>
		</view>
		<view class="clear item-content">
			<text>清除缓存</text>
			<view class="clear-item">
				<view>{{size}}</view>
				<image src="../../../static/jiantou3.png" @click="clearCache"></image>
			</view>
		</view>
		<view class="item1">
			<view class="item-content" >
				<view>系统版本</view>
				<view>{{edition}}</view>
			</view>						
		</view>
		<view class="developing" v-if="developing">
			正在开发当中，请尽情期待... ...
		</view>
		<view class="closeIntegral" @click="closeIntegral()" v-if="developing">确定</view>
		<!-- <view class="bg-white p-0-30 f30">
			<view class="d-b-c p-30-0 border-b">
				<text class="key-name">会员ID</text>
				<view class="d-e-c">
					<text class="mr20">{{userInfo.user_id}}</text>
				</view>
			</view>
			<view class="d-b-c p-30-0 border-b">
				<text class="key-name">昵称</text>
				<view class="d-e-c">
					<text class="mr20">{{userInfo.nickName}}</text>
				</view>
			</view>
			<view class="d-b-c p-30-0">
				<text class="key-name">手机号码</text>
				<view class="d-e-c" v-if="userInfo.mobile">
					<text class="mr20">{{userInfo.mobile}}</text>
				</view>
				<view class="d-e-c" v-if="!userInfo.mobile" @click="gotoBind">
					<text class="mr20">未绑定</text>
					<text class="iconfont icon-jiantou"></text>
				</view>
			</view> -->
		<view class="setup-btn" @tap="logout()">退出登录</view>
		<view class="tick"><text>Copyright c2022-2021版权所有◎桂林顺亨网络科技有限公司所有</text></view>
		<!-- </view> -->
	</view>
</template>

<script>
	import {
		gotopage
	} from '@/common/gotopage.js';
	export default {
		components: {},
		data() {
			return {
				userInfo: {},
				size: '',
				developing:false,
				timer:null,
				windowHeight:'',
				edition:'',
			};
		},
		onLoad() {	
			plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
			//console.log(JSON.stringify(wgtinfo));
			//console.log(wgtinfo.version);//应用版本号
				this.edition = wgtinfo.version
			});
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight;
					//console.log(this.windowHeight)
				}
			});
			this.formatSize();
		},
		onShow() {
			/*获取个人中心数据*/
			this.getData();
		},
		methods: {
			closeIntegral() {
				this.developing = false
				if (this.timer) {
					clearTimeout(this.timer);
					this.timer = null;
				}
			},
			showIntegral() {
				this.developing = true;
				this.timer = setTimeout(() => {
					this.developing = false
				}, 3000);
			},
			/*跳转页面*/
			gotoPage(path) {
				let self = this;
				if (path.startsWith('/')) {
					uni.navigateTo({
						url: path
					});
				} else {
					self[path]();
				}
			},
			/* 计算缓存大小 只能在手机端使用，其他会报错 */
			formatSize() {
				let that = this;
				plus.cache.calculate(function(size) {
					let sizeCache = parseInt(size);
					if (sizeCache == 0) {
						that.fileSizeString = "0B";
					} else if (sizeCache < 1024) {
						that.fileSizeString = sizeCache + "B";
					} else if (sizeCache < 1048576) {
						that.fileSizeString = (sizeCache / 1024).toFixed(2) + "KB";
					} else if (sizeCache < 1073741824) {
						that.fileSizeString = (sizeCache / 1048576).toFixed(2) + "MB";
					} else {
						that.fileSizeString = (sizeCache / 1073741824).toFixed(2) + "GB";
					}
					that.size = that.fileSizeString;
				});
			},
			/* 清除缓存 */
			clearCache() {
				let that = this;
				let os = plus.os.name;
				if (os == 'Android') {
					let main = plus.android.runtimeMainActivity();
					let sdRoot = main.getCacheDir();
					let files = plus.android.invoke(sdRoot, "listFiles");
					let len = files.length;
					for (let i = 0; i < len; i++) {
						let filePath = '' + files[i]; // 没有找到合适的方法获取路径，这样写可以转成文件路径  
						plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
							if (entry.isDirectory) {
								entry.removeRecursively(function(entry) { //递归删除其下的所有文件及子目录  
									uni.showToast({
										title: '缓存清理完成',
										duration: 2000
									});
									that.formatSize(); // 重新计算缓存  
								}, function(e) {
									console.log(e.message)
								});
							} else {
								entry.remove();
							}
						}, function(e) {
							console.log('文件路径读取失败')
						});
					}
				} else { // ios  
					plus.cache.clear(function() {
						uni.showToast({
							title: '缓存清理完成',
							duration: 2000
						});
						that.formatSize();
					});
				}
			},

			/*获取数据*/
			getData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('user.index/setting', {}, function(res) {
					self.userInfo = res.data.userInfo;
					uni.hideLoading();
				});
			},
			gotoBind() {
				uni.navigateTo({
					url: '/pages/login/bindmobile'
				});
			},
			logout() {
				let self = this ;
				uni.showModal({
					title:'温馨提示',
					content:'是否确定退出登录',
					success(res) {
						if(res.confirm){
							uni.removeStorageSync('token');
							uni.removeStorageSync('user_id');
							self.gotoPage('/login/login');
						}else if(res.cancel){
							
						}
					}
				})
				// uni.removeStorageSync('token');
				// uni.removeStorageSync('user_id');
				// gotopage('/pages/login/weblogin');
				//uni.navigateBack();
			},
		}
	};
</script>

<style>
	.head {
		height: 100rpx;
		width: 100%;
		background-color: #FFFFFF;
		position: fixed;
		top: 0;
		z-index: 999;
		display: flex;
		align-items: center;
		font-size: 36rpx;
		box-shadow: 0 0 10rpx 10rpx #f4f4f4;
	}

	.head image {
		width: 60rpx;
		height: 60rpx;
		display: block;
		margin-right: 280rpx;
	}

	.address-form {
		height: 100%;
		background-color: #F4F4F4;
		overflow: hidden;
	}

	.address-form .key-name {
		width: 200rpx;
	}

	.address-form .btn-red {
		height: 88rpx;
		line-height: 88rpx;
		border-radius: 44rpx;
		box-shadow: 0 8rpx 16rpx 0 rgba(226, 35, 26, .6);
	}

	.item1,
	.clear {
		background-color: #FFFFFF;
		width: 96%;
		margin: 20rpx auto 20rpx;
		border-radius: 14rpx;
		line-height: 100rpx;
	}

	.item-content {
		height: 100rpx;
		width: 90%;
		line-height: 100rpx;
		margin: 0 auto;
		border-bottom: 1rpx solid #F4F4F4;
		font-size: 30rpx;
	}

	.item-content {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.item-content image {
		margin-left: 20rpx;
		width: 60rpx;
		height: 60rpx;
	}

	.clear {
		width: 88%;
		padding: 0 30rpx;
	}

	.clear-item {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.setup-btn {

		width: 96%;
		height: 100rpx;
		line-height: 100rpx;
		background-color: #FFFFFF;
		color: #F00808;
		font-size: 30rpx;
		display: flex;
		justify-content: center;
		margin: 200rpx auto 30rpx;
	}
	.developing{
		width: 96%;
		height: 100%;
		line-height: 600rpx;
		background-color: #FFFFFF;
		position: fixed;
		top: 0rpx;
		left: 2%;
		text-align: center;
		font-size: 30rpx;
		border-radius: 20rpx;
		opacity: 0.9;
	}
	.closeIntegral{
		clear: both;
		width: 200rpx;
		height: 60rpx;
		background-color: #0368FF;
		position: fixed;
		bottom: 20%;
		left: 50%;
		margin-left: -100rpx;
		text-align: center;
		color: #FFFFFF;
		font-size: 30rpx;
		line-height: 60rpx;
		border-radius: 10rpx;
		z-index: 66;
	}
	.tick{
		text-align: center;
		width: 480rpx;
		position: absolute;
		bottom: 60rpx;		
		font-size: 30rpx;
		margin-left: 150rpx;
		color: #999999;
	}
</style>
